﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using NationalInstruments.TestStand.Interop.API;

//namespace CLVisionEICS
//{
//    public class EICSClientNCCaller
//    {
//        ICLEICSClient mQTTCallerInstance = null;

//        private bool CheckInstance(out int ErrorCode, out string ErrorText, out bool Occurred, string methodName)
//        {
//            if (mQTTCallerInstance == null)
//            {
//                ErrorCode = -1;
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{methodName}: MQTT客户端对象为null！请检查IntMqttClient初始化是否执行成功！";
//                Occurred = true;
//                return false;
//            }
//            ErrorCode = 0;
//            ErrorText = $"{nameof(EICSClientNCCaller)}:{methodName}: Start!";
//            Occurred = false;
//            return true;
//        }

//        public bool IntMqttClient(string server, int port, string username, string password, string topicName, string clientId, out int ErrorCode, out string ErrorText, out bool Occurred)
//        {
//            ErrorCode = 0;
//            ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(IntMqttClient)}: Start!";
//            Occurred = false;
//            try
//            {
//                mQTTCallerInstance = CLEICSClientFactory.CreateMQTTClient();
//                if (mQTTCallerInstance == null)
//                {
//                    ErrorCode = -1;
//                    ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(IntMqttClient)}: 创建MQTT客户端对象失败！请检查dll放置路径是否有误！";
//                    Occurred = true;
//                    return false;
//                }
//                bool ret = mQTTCallerInstance.IntMqttClient(server, port, username, password, topicName, clientId, out ErrorCode, out ErrorText);
//                if (ErrorCode == -1)
//                {
//                    Occurred = true;
//                    return false;
//                }
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(IntMqttClient)}: End!";
//                return ret;
//            }
//            catch (Exception ex)
//            {
//                ErrorCode = -1;
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(IntMqttClient)}: Fail! " + ex.Message;
//                Occurred = true;
//                return false;
//            }
//        }

//        public bool PublishData(string topicName, string mesData, MQTTnet.Protocol.MqttQualityOfServiceLevel qos, out int ErrorCode, out string ErrorText, out bool Occurred)
//        {
//            if (!CheckInstance(out ErrorCode, out ErrorText, out Occurred, nameof(PublishData)))
//                return false;
//            try
//            {
//                bool ret = mQTTCallerInstance.PublishData(topicName, mesData, qos, out ErrorCode, out ErrorText);
//                if (ErrorCode == -1)
//                {
//                    Occurred = true;
//                    return false;
//                }
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(PublishData)}: End!";
//                return ret;
//            }
//            catch (Exception ex)
//            {
//                ErrorCode = -1;
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(PublishData)}: Fail! " + ex.Message;
//                Occurred = true;
//                return false;
//            }
//        }

//        public bool SubscribeTopic(out int ErrorCode, out string ErrorText, out bool Occurred,params string[] topicNames)
//        {
//            if (!CheckInstance(out ErrorCode, out ErrorText, out Occurred, nameof(SubscribeTopic)))
//                return false;
//            try
//            {
//                bool ret = mQTTCallerInstance.SubscribeTopic(out ErrorCode, out ErrorText, topicNames);
//                if (ErrorCode == -1)
//                {
//                    Occurred = true;
//                    return false;
//                }
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(SubscribeTopic)}: End!";
//                return ret;
//            }
//            catch (Exception ex)
//            {
//                ErrorCode = -1;
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(SubscribeTopic)}: Fail! " + ex.Message;
//                Occurred = true;
//                return false;
//            }
//        }

//        public bool UnsubscribeTopic( out int ErrorCode, out string ErrorText, out bool Occurred, params string[] topicNames)
//        {
//            if (!CheckInstance(out ErrorCode, out ErrorText, out Occurred, nameof(UnsubscribeTopic)))
//                return false;
//            try
//            {
//                bool ret = mQTTCallerInstance.UnsubscribeTopic(out ErrorCode, out ErrorText, topicNames);
//                if (ErrorCode == -1)
//                {
//                    Occurred = true;
//                    return false;
//                }
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(UnsubscribeTopic)}: End!";
//                return ret;
//            }
//            catch (Exception ex)
//            {
//                ErrorCode = -1;
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(UnsubscribeTopic)}: Fail! " + ex.Message;
//                Occurred = true;
//                return false;
//            }
//        }

//        public bool DisconnectMqttClient(out int ErrorCode, out string ErrorText, out bool Occurred)
//        {
//            if (!CheckInstance(out ErrorCode, out ErrorText, out Occurred, nameof(DisconnectMqttClient)))
//                return false;
//            try
//            {
//                bool ret = mQTTCallerInstance.DisconnectMqttClient(out ErrorCode, out ErrorText);
//                if (ErrorCode == -1)
//                {
//                    Occurred = true;
//                    return false;
//                }
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(DisconnectMqttClient)}: End!";
//                return ret;
//            }
//            catch (Exception ex)
//            {
//                ErrorCode = -1;
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(DisconnectMqttClient)}: Fail! " + ex.Message;
//                Occurred = true;
//                return false;
//            }
//        }

//        public bool ReadDataFromFile(PropertyObject propertyObject, string filePath, out int ErrorCode, out string ErrorText, out bool Occurred)
//        {
//            if (!CheckInstance(out ErrorCode, out ErrorText, out Occurred, nameof(ReadDataFromFile)))
//                return false;
//            try
//            {
              
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(ReadDataFromFile)}: End!";
//                return true;
//            }
//            catch (Exception ex)
//            {
//                ErrorCode = -1;
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(ReadDataFromFile)}: Fail! " + ex.Message;
//                Occurred = true;
//                return false;
//            }
//        }

//        public bool WriteDataToFile(PropertyObject propertyObject, string filePath, out int ErrorCode, out string ErrorText, out bool Occurred)
//        {
//            if (!CheckInstance(out ErrorCode, out ErrorText, out Occurred, nameof(WriteDataToFile)))
//                return false;
//            try
//            {
              
               
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(WriteDataToFile)}: End!";
//                return true;
//            }
//            catch (Exception ex)
//            {
//                ErrorCode = -1;
//                ErrorText = $"{nameof(EICSClientNCCaller)}:{nameof(WriteDataToFile)}: Fail! " + ex.Message;
//                Occurred = true;
//                return false;
//            }
//        }
//    }
//}
